package com.bw.dao;

import com.bw.util.JDBC;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/***************************
 FileAction:

 CreateTime:2022-08-01 11:01
 Author:Asking-mac
 ****************************/
public class UserDao {

    // 增
    public void insertUser(String username,String password) throws SQLException {

        String sql = "insert into user values(null,?,?)";


        Connection conn = JDBC.getConnection();
        PreparedStatement ps = conn.prepareStatement(sql);


        ps.setObject(1,username);
        ps.setObject(2,password);

        ps.executeUpdate();
    }

    // 查
    public boolean selectUserByUsernameAndPassword(String username,String password) throws SQLException {
        String sql = "select * from user where username = ? and password = ?";
        Connection conn = JDBC.getConnection();
        PreparedStatement ps = conn.prepareStatement(sql);
        ps.setObject(1,username);
        ps.setObject(2,password);

        ResultSet rs = ps.executeQuery();

        if(rs.next()){
            return true;
        }
        return false;
    }



}
